using OneCaps.Core.Entity;
using OneCaps.Core.Enum;

namespace OneCaps.Core.Interfaces
{
    /// <summary>
    /// 报表服务接口
    /// </summary>
    public interface IReportService
    {
        /// <summary>
        /// 获取停车场概况
        /// </summary>
        Task<ParkingLotOverview> GetParkingLotOverviewAsync();

        /// <summary>
        /// 获取收费日报表
        /// </summary>
        Task<DailyRevenueReport> GetDailyRevenueReportAsync(DateTime date);

        /// <summary>
        /// 获取收费月报表
        /// </summary>
        Task<MonthlyRevenueReport> GetMonthlyRevenueReportAsync(int year, int month);

        /// <summary>
        /// 获取车位利用率报表
        /// </summary>
        Task<ParkingSpaceUtilizationReport> GetParkingSpaceUtilizationReportAsync(DateTime startDate, DateTime endDate);

        /// <summary>
        /// 获取车辆类型统计
        /// </summary>
        Task<VehicleTypeStatistics> GetVehicleTypeStatisticsAsync(DateTime startDate, DateTime endDate);

        /// <summary>
        /// 获取支付方式统计
        /// </summary>
        Task<PaymentMethodStatistics> GetPaymentMethodStatisticsAsync(DateTime startDate, DateTime endDate);

        /// <summary>
        /// 获取异常停车记录
        /// </summary>
        Task<IEnumerable<ParkingRecord>> GetAbnormalParkingRecordsAsync(DateTime startDate, DateTime endDate);

        /// <summary>
        /// 获取超时停车记录
        /// </summary>
        Task<IEnumerable<ParkingRecord>> GetOverdueParkingRecordsAsync(TimeSpan maxDuration);

        /// <summary>
        /// 导出报表
        /// </summary>
        Task<byte[]> ExportReportAsync(ReportType reportType, DateTime startDate, DateTime endDate, string format = "xlsx");
    }

    /// <summary>
    /// 报表类型
    /// </summary>
    public enum ReportType
    {
        DailyRevenue = 1,
        MonthlyRevenue = 2,
        ParkingSpaceUtilization = 3,
        VehicleTypeStatistics = 4,
        PaymentMethodStatistics = 5,
        AbnormalRecords = 6
    }

    /// <summary>
    /// 停车场概况
    /// </summary>
    public class ParkingLotOverview
    {
        public int TotalSpaces { get; set; }
        public int AvailableSpaces { get; set; }
        public int OccupiedSpaces { get; set; }
        public int MaintenanceSpaces { get; set; }
        public int CurrentVehicles { get; set; }
        public decimal TodayRevenue { get; set; }
        public int TodayRecords { get; set; }
        public Dictionary<VehicleType, int> SpacesByType { get; set; } = new();
        public Dictionary<ParkingSpaceStatus, int> SpacesByStatus { get; set; } = new();
    }

    /// <summary>
    /// 收费日报表
    /// </summary>
    public class DailyRevenueReport
    {
        public DateTime Date { get; set; }
        public int TotalRecords { get; set; }
        public decimal TotalRevenue { get; set; }
        public decimal TotalDiscount { get; set; }
        public Dictionary<PaymentMethod, decimal> RevenueByPaymentMethod { get; set; } = new();
        public Dictionary<VehicleType, int> RecordsByVehicleType { get; set; } = new();
        public List<HourlyRevenue> HourlyRevenues { get; set; } = new();
    }

    /// <summary>
    /// 小时收费统计
    /// </summary>
    public class HourlyRevenue
    {
        public int Hour { get; set; }
        public int Records { get; set; }
        public decimal Revenue { get; set; }
    }

    /// <summary>
    /// 收费月报表
    /// </summary>
    public class MonthlyRevenueReport
    {
        public int Year { get; set; }
        public int Month { get; set; }
        public int TotalRecords { get; set; }
        public decimal TotalRevenue { get; set; }
        public decimal TotalDiscount { get; set; }
        public Dictionary<PaymentMethod, decimal> RevenueByPaymentMethod { get; set; } = new();
        public Dictionary<VehicleType, int> RecordsByVehicleType { get; set; } = new();
        public List<DailyRevenue> DailyRevenues { get; set; } = new();
    }

    /// <summary>
    /// 日收费统计
    /// </summary>
    public class DailyRevenue
    {
        public DateTime Date { get; set; }
        public int Records { get; set; }
        public decimal Revenue { get; set; }
    }

    /// <summary>
    /// 车位利用率报表
    /// </summary>
    public class ParkingSpaceUtilizationReport
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public int TotalSpaces { get; set; }
        public double AverageUtilizationRate { get; set; }
        public double PeakUtilizationRate { get; set; }
        public DateTime PeakTime { get; set; }
        public Dictionary<ParkingSpaceType, double> UtilizationByType { get; set; } = new();
        public List<HourlyUtilization> HourlyUtilizations { get; set; } = new();
    }

    /// <summary>
    /// 小时利用率统计
    /// </summary>
    public class HourlyUtilization
    {
        public int Hour { get; set; }
        public double UtilizationRate { get; set; }
        public int OccupiedSpaces { get; set; }
        public int TotalSpaces { get; set; }
    }

    /// <summary>
    /// 车辆类型统计
    /// </summary>
    public class VehicleTypeStatistics
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public Dictionary<VehicleType, VehicleTypeData> DataByType { get; set; } = new();
        public int TotalRecords { get; set; }
    }

    /// <summary>
    /// 车辆类型数据
    /// </summary>
    public class VehicleTypeData
    {
        public VehicleType Type { get; set; }
        public int Records { get; set; }
        public decimal TotalRevenue { get; set; }
        public double AverageDuration { get; set; }
        public double Percentage { get; set; }
    }

    /// <summary>
    /// 支付方式统计
    /// </summary>
    public class PaymentMethodStatistics
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public Dictionary<PaymentMethod, PaymentMethodData> DataByMethod { get; set; } = new();
        public int TotalRecords { get; set; }
        public decimal TotalRevenue { get; set; }
    }

    /// <summary>
    /// 支付方式数据
    /// </summary>
    public class PaymentMethodData
    {
        public PaymentMethod Method { get; set; }
        public int Records { get; set; }
        public decimal Revenue { get; set; }
        public double Percentage { get; set; }
    }
} 